package com.xiaoxx.rabbitmq.broker;


import com.xiaoxx.rabbitmq.IRabbitMQMessageClient;
import com.xiaoxx.rabbitmq.bean.MyMessage;
import com.xiaoxx.rabbitmq.constant.MessageType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * $ProducerClient 发送消息的实际实现类
 * @author quhiu
 */
@Component
public class ProducerClient implements IRabbitMQMessageClient {

    @Autowired
    private RabbitBroker rabbitBroker;

    @Override
    public void send(MyMessage myMessage) {
        if (!Optional.ofNullable(myMessage).map(MyMessage::getTopic).isPresent()){
            throw new RuntimeException("#MQ消息发送失败# 未设置交行机");
        }
        String messageType = myMessage.getMessageType();
        switch (messageType) {
            case MessageType.RAPID:
                    rabbitBroker.rapidSend(myMessage);
                    break;
            case MessageType.CONFIRM:
                rabbitBroker.confirmSend(myMessage);
                break;
            case MessageType.RELIANT:
                rabbitBroker.reliantSend(myMessage);
                break;
            default: throw new RuntimeException("未知消息无法发送");
        }
    }

    // @Override
    // public void send(List<Message> messages) throws MessageRunTimeException {
    //
    // }
    //
    // @Override
    // public void send(Message message, SendCallback sendCallback) throws MessageRunTimeException {
    //
    // }

}
